# Maintainer: David Runge <dvzrv@archlinux.org>

_name=django-haystack
pkgname=python-django-haystack
pkgver=3.2.1
pkgrel=3
pkgdesc="Modular search for Django"
arch=(any)
url="https://github.com/django-haystack/django-haystack"
license=(BSD)
depends=(python-django)
makedepends=(python-build python-installer python-setuptools-scm python-wheel)
checkdepends=(gdal python-dateutil python-elasticsearch python-geopy
python-nose python-pysolr python-requests python-whoosh)
optdepends=(
  'python-elasticsearch: interface with an elasticsearch instance as search backend'
  'python-pysolr: interface with a solr instance as search backend'
  'python-whoosh: use whoosh as search backend'
  'python-xapian-haystack: use python-xapian as search backend'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('60ce7297243ab5a43780b0aed6f25970ef0438aaadf8f7c92f89970e58c045d3f6ba7a5a635a275e21dc73b116fb33cad32a41991a677bd0a9c66aef4b7ff0c2')
b2sums=('6071ae9502a3bad885e95b79a1969b6ca6dd044a6d113726045d722168aa05d88b12047b0fbf7d7710936bd32158f2f9c27a6f29868e70e00f88ded1bc3b740a')

prepare() {
  # remove useless version pinning
  sed -e 's/==/>=/g' -i $_name-$pkgver/setup.py
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_name-$pkgver/test_haystack/
  nosetests \
    --exclude=test_more_like_this \
    --exclude=test_pagination \
    --exclude=test_search_query \
    --cover-package=haystack \
    --cover-erase \
    --verbose
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {AUTHORS,CONTRIBUTING.md,README.rst} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
